﻿using MediatR;
using SheepStorage.API.Application.Command.DepartmentCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.DepartmentHandler
{
    public class DepartmentListCommandHandler : IRequestHandler<DepartmentListCommand, Results<PageOutput<Department>>>
    {

        private readonly IDepartmentService departmentService;

        public DepartmentListCommandHandler(IDepartmentService departmentService)
        {
            this.departmentService = departmentService;
        }

        /// <summary>
        /// 部门显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<PageOutput<Department>>> Handle(DepartmentListCommand request, CancellationToken cancellationToken)
        {
            return Results<PageOutput<Department>>.DataResult(await departmentService.GetDepartmentList(request.DepartmentName,request.pageIndex,request.pageSize));


        }

    }
}
